home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / help10.arc / HELP.ASM < prev    next >
Assembly Source File  |  1987-03-06  |  11KB  |  300 lines

  1.      page 60,132
  2. ; HELP.COM by Bob Montgomery, 2/23/87
  3. ; This program is a generic help screen template for use with the MASM
  4. ; assembler. The desired help message is written as db's at Hlpst in
  5. ; place of the test message that is there now. The only restrictions 
  6. ; on the help message are:
  7. ;    1. The message must not exceed 80 characters wide.
  8. ;    2. The message must not exceed 25 lines long.
  9. ;    3. Each help line must be the same length.
  10. ; The program will auto center the message on the display screen. The hot 
  11. ; key combo to bring up the help screen is defined as Hotkey below (set 
  12. ; for Cntl-Leftshift right now) and can be changed to another combination
  13. ; by changing the equate for Hotkey.
  14.  
  15. Code segment
  16.      assume cs:Code,ds:Code
  17.      org  100h
  18.  
  19. Begin: jmp Init          ;Initialize program
  20.  
  21. Esc  equ  1Bh
  22. Vidmem equ 0B800h        ;Location of screen 0
  23. Monomem equ 0B000h       ;Location of mono screen
  24. BWattr equ 70h           ;Grey background, black foreground
  25.  
  26. ; Bits in shift status
  27. Rtsh   equ 1
  28. Lftsh  equ 2
  29. Cntl   equ 4
  30. Alt    equ 8
  31. Scrl   equ 10h
  32. Numl   equ 20h
  33. Capl   equ 40h
  34.  
  35. Mode   db  ?             ;Current video mode
  36. Vpage  db  ?             ;Current video page
  37. Vidseg dw  ?             ;Current page segment
  38. Hlpflg db  0             ;1 => Help on
  39. Attr   db  ?             ;Attribute to use
  40. Cursor dw  ?             ;Current cursor type
  41.  
  42. ; ==================================================================
  43. ; This is the test help message to be displayed on the video screen.
  44. ; Change this area for your own help message, color, and hot key combo.
  45.  
  46. Colattr equ 4Eh          ;Red background, yellow foreground
  47. Hotkey equ Cntl+Lftsh    ;Define the hot key combo to bring up screen
  48.  
  49. Hlpst: db 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
  50. Linchr equ $-Hlpst       ;Chars on each help line
  51.      db   'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
  52.      db   'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC'
  53.      db   'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD'
  54.      db   'EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE'
  55.      DB   'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
  56.      db   'GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG'
  57.      db   'HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH'
  58.      db   'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII'
  59.      db   'JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ'
  60.      db   'KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK'
  61.      DB   'LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL'
  62.      DB   'MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
  63.      DB   'NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN'
  64.      DB   'OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO'
  65.      DB   'PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP'
  66.      DB   'QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ'
  67.      DB   'RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR'
  68.      DB   'SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS'
  69.      DB   'TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT'
  70.      DB   'UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU'
  71.      DB   'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV'
  72.      DB   'WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW'
  73. ; ===================================================================
  74.  
  75. Msglen equ $-Hlpst       ;# chars in help buffer
  76. Lines equ Msglen/Linchr  ;# lines of help
  77. Buflen equ 2*Msglen      ;Screen data buffer length
  78. Stlin equ (25-Lines)/2   ;Start line
  79. Stchr equ (80-Linchr)/2  ;Start byte on line
  80. Stscr equ 160*Stlin + 2*Stchr ;Start of mem to put help
  81.  
  82. Scrbuf: db Buflen dup (?) ;Buffer for screen data
  83.  
  84. ; New Int 9 routine - check for Cntrl-LShift; ignore others.
  85. ; Since Int 9 is called every time a key is pressed or released, and
  86. ; reads the keyboard thru some mysterious means in BIOS, we must call
  87. ; the old Int 9 as a subroutine each time an Int 9 is generated. But,
  88. ; an interrupt routine has a IRET instead of a RET as the return
  89. ; instruction, which pops the return address like a RET does, and then
  90. ; pops the flags. So to call Int 9 like a subroutine, we have to push
  91. ; the flags first; then when the the IRET is executed, control returns
  92. ; to our program with the stack pointer at the right place.
  93.  
  94. Start: push ax           ;Save all for calling program
  95.      push bx
  96.      push cx
  97.      push dx
  98.      push ds
  99.      push es
  100.      push di
  101.      push si
  102.      pushf               ;Put flags on stack since Int pops flags
  103. ;Call old Int 9 to get key-will pop flags
  104.      db   9Ah            ;Opcode for far call
  105. Oldint  dw ?,?           ;Save old Int 9 vector here
  106.      mov  ah,2           ;Get shift status
  107.      Int  16h            ;in al
  108.      and  al,Hotkey      ;Only keep Hot keys
  109.      cmp  al,Hotkey      ;Were both pressed?
  110.      jne  Exit           ;No
  111.      push cs
  112.      pop  ds             ;Yes, set ds=cs
  113.      cmp  Hlpflg,1       ;Is help already up?
  114.      jne  Go             ;No, put it up
  115. ; If help is already up, ignore the Hotkey.
  116. Exit: pop si             ;Restore all for calling program
  117.      pop  di
  118.      pop  es
  119.      pop  ds
  120.      pop  dx
  121.      pop  cx
  122.      pop  bx
  123.      pop  ax
  124.      iret                ;Pop return address and flags
  125.  
  126. ; Come here if should put up help.
  127. Go:  mov  al,Colattr     ;Assume color
  128.      mov  Attr,al
  129.      mov  ah,15          ;Get video mode in al
  130.      int  10h            ;and page in bh
  131.      mov  Mode,al        ;Save Mode
  132.      mov  Vpage,bh       ;and page
  133.      cmp  al,2           ;Mode=2?
  134.      je   Color          ;Yes
  135.      cmp  al,3           ;Mode=3?
  136.      je   Color          ;Yes
  137.      cmp  al,7           ;Mode=7? (mono)
  138.      jne  Exit           ;No, must be graphics so exit
  139.      mov  al,BWattr      ;Set B&W attribute
  140.      mov  Attr,al
  141.      mov  bx,Monomem     ;and start of mono video memory
  142.      jmp  short A0
  143. Color: mov  bl,0         ;Bx=256*display page
  144.      add  bx,Vidmem      ;Get display mem segment
  145. A0:  mov  ds,bx          ;in ds
  146.  
  147. ; Put up help screen.
  148. ; First save current screen to buffer.
  149.      call Hidecur        ;Hide cursor
  150.      call Vidoff         ;Disable video (avoids snow on CGA)
  151.      mov  dl,Lines       ;Get # lines of help
  152.      push cs             ;es=cs
  153.      pop  es
  154.      mov  si,Stscr       ;ds:si points to help screen area in disp mem
  155.      mov  di,offset Scrbuf ;es:di points to buffer for screen data
  156.      push si             ;Save them
  157.      push es
  158.      push ds
  159.      mov  ch,0           ;ch=0
  160.      mov  cl,Linchr      ;cx=chars/help line
  161. A1:  push si             ;Save position in scrn mem & chars/line
  162.      push cx
  163.      cld                 ;Set to inc si & di
  164.      rep  movsw          ;Move screen to buffer
  165.      pop  cx             ;Get start of line & chars/line
  166.      pop  si
  167.      add  si,160         ;Next line, same column
  168.      dec  dl             ;Done all lines?
  169.      jne  A1             ;No
  170.  
  171. ; Now put up help.
  172.      pop  es             ;Now ds=cs, es:di=help scrn area in screen mem
  173.      pop  ds
  174.      pop  di
  175.      push di             ;Put back in orig order
  176.      push ds
  177.      push es
  178.      mov  si,offset Hlpst ;Point si to help data
  179.      mov  dl,Lines       ;Get chars/help line
  180.      mov  ah,Attr        ;Get char attribute (color)
  181. B1:  push di             ;Save disp mem pos & chars/help line
  182.      push cx
  183. B2:  lodsb               ;Get a help char in al
  184.      stosw               ;Save char & attribute in screen mem
  185.      loop B2             ;Do whole line
  186.      pop  cx             ;Get start of disp line & chars/line
  187.      pop  di
  188.      add  di,160         ;Next line, same column
  189.      dec  dl             ;Done all lines?
  190.      jne  B1             ;No
  191.      mov  Hlpflg,1       ;Yes, indicate help up
  192.      call Vidon          ;and enable video
  193.  
  194. ; Now, wait for the escape key; come here after each keypress (Int 9).
  195. Wait1: mov ah,0          ;Wait for a key
  196.      int  16h
  197.      cmp  al,Esc         ;Was it Escape?
  198.      jne  Wait1          ;No
  199.  
  200. ; If Esc was pressed, put the old screen back
  201.      pop  es             ;ds=cs; es:di=start of help area in disp mem
  202.      pop  ds
  203.      pop  di
  204.      mov  si,offset Scrbuf ;Point to old screen data buffer
  205.      call Vidoff         ;Disable video (avoid snow on CGA)
  206.      mov  dl,Lines       ;Chars/help line
  207. C1:  push di             ;Save scrn mem pointer & chars/line
  208.      push cx
  209.      rep  movsw          ;Move a line to scrn mem
  210.      pop  cx             ;Get start of line & chars/line
  211.      pop  di
  212.      add  di,160         ;Next line, same column
  213.      dec  dl             ;Done all lines?
  214.      jne  C1             ;No
  215.      mov  Hlpflg,0       ;Yes, clear flag
  216.      call Vidon          ;Enable video
  217.      call Showcur        ;Turn cursor back on
  218.      jmp  Exit           ;and return
  219.  
  220. ; Sub to turn cursor off; come with ds=video.
  221. Hidecur: push cx   
  222.      push ds
  223.      push cs             ;ds=cs
  224.      pop  ds
  225.      mov  ah,3           ;Get current cursor data
  226.      mov  bh,Vpage       ;for current page
  227.      int  10h
  228.      mov  Cursor,cx      ;Save cursor type
  229.      mov  ch,20h         ;Set cursor off
  230.      mov  ah,1
  231.      int  10h
  232.      pop  ds    
  233.      pop  cx
  234.      ret
  235.  
  236. ; Sub to turn cursor on; come with ds=cs.
  237. Showcur: mov  cx,Cursor  ;Set original cursor Type
  238.      mov  bh,Vpage
  239.      mov  ah,1
  240.      int  10h
  241.      ret
  242.  
  243. ; Turn video off
  244. Vidoff: cmp cs:Mode,7    ;Mono?
  245.      je   D0             ;Yes, skip wait for vert retrace
  246.      push ds        
  247.      push dx
  248.      push ax
  249.      call Getmode        ;Get current video mode byte
  250.      and  al,0F7h        ;Clear video enable bit
  251.      out  dx,al          ;Send to mode control port
  252.      pop  ax      
  253.      pop  dx
  254.      pop  ds
  255. D0:  ret
  256.  
  257. ; Turn video on
  258. Vidon: cmp cs:Mode,7     ;Mono?
  259.      je   E0             ;Yes, skip wait for vert retrace
  260.      push ds        
  261.      push dx
  262.      push ax
  263.      call Getmode        ;Get current video mode byte
  264.      or   al,8           ;Set video enable bit
  265.      out  dx,al          ;Send to mode control port
  266.      pop  ax       
  267.      pop  dx
  268.      pop  ds
  269. E0:  ret
  270.  
  271. ; Sub to wait for vertical retrace to avoid snow on CGA screen.
  272. Vert: mov dx,3DAh        ;CRT status port
  273. F1:  in   al,dx          ;Read status
  274.      test al,8           ;Vert retrace?
  275.      je   F1             ;No
  276.      mov  dx,3D8h        ;Point to video mode port
  277.      ret                 ;Yes, return
  278.  
  279. Getmode: call Vert       ;Wait for vert retrace
  280.      mov  ax,40h         ;Get video mode
  281.      mov  ds,ax          ;at 465h
  282.      mov  al,ds:[65h]
  283.      ret                 ;and return
  284.  
  285. ; Come here to install the program as the new Int 9 routine.
  286. Init: mov ax,3509h       ;Get current Int 9 vector
  287.      int  21h            ;in es:bx
  288.      push cs
  289.      pop  ds
  290.      mov  Oldint,bx      ;Save it
  291.      mov  Oldint+2,es
  292.      mov  ax,2509h       ;Set new Int 9 routine
  293.      mov  dx,offset Start
  294.      int  21h
  295.      mov  dx,offset Init ;Terminate and
  296.      int  27h            ;stay resident
  297.  
  298. Code ends
  299.      end  Begin
  300.